package com.zlq.cn.controller.sign.ai;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zlq.cn.api.SignApiResult;
import com.zlq.cn.bootstrap.SignApiBootstrap;
import com.zlq.cn.controller.BaseController;
import com.zlq.cn.entity.MaasInvoke;
import com.zlq.cn.service.ai.MaasService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;

/**
 * @author zhoucl
 * @date 2023年02月08日 14:58
 */
@Api(tags = "紫东太初")
@Validated
@RestController
@RequestMapping("/maas")
public class MaasAiController extends BaseController {
    @Resource
    private MaasService maasService;

    @ApiOperation("语言模型")
    @PostMapping("/invoke")
    public SignApiResult<JSONObject> invoke(@ApiIgnore @RequestBody JSONObject param) {
        return SignApiResult.resultSuccess(maasService.invoke(param));
    }

    @ApiOperation("提问历史")
    @PostMapping("/list")
    public SignApiResult<Page<MaasInvoke>> list(@RequestBody MaasInvoke maasInvoke) {
        return SignApiResult.resultSuccess(maasService.lambdaQuery()
                .eq(MaasInvoke::getUserImei, SignApiBootstrap.requestFanYiUser().getFanyiUserImei())
                .eq(StringUtils.isNotEmpty(maasInvoke.getType()), MaasInvoke::getType, maasInvoke.getType())
                .like(StringUtils.isNotEmpty(maasInvoke.getQuestion()), MaasInvoke::getQuestion, maasInvoke.getQuestion())
                .orderByDesc(MaasInvoke::getCreateTime)
                .page(super.<MaasInvoke>getPage()));
    }

    @ApiOperation("图生图，根据您输入的 单张参考图片+文本提示词 生成单张图片")
    @PostMapping("/seed-edit")
    public SignApiResult<JSONObject> seedEdit(@ApiIgnore @RequestBody JSONObject param) {
        return SignApiResult.resultSuccess(maasService.seedEdit(param));
    }
}
